package com.dbManage.page.project;

import com.dbManage.entity.Message;
import com.dbManage.entity.Project;
import com.dbManage.page.user.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class ProjectController {
    @Resource
    ProjectService projectService;
    @Resource
    UserService userService;
    /**
     * 项目列表
     * @param model
     * @return
     */
    @RequestMapping("projectList")
    public String projectList(Model model){
        List<Project> list=projectService.getProject();
        model.addAttribute("list",list);
        return "projectList";
    }

    /**
     * 新增项目页面
     * @param model
     * @return
     */
    @RequestMapping("addProjectView")
    public String addProjectView(Model model){
        model.addAttribute("userList",userService.getUserList());
        return "projectAdd";
    }

    /**
     * 新增项目
     * @param project
     * @return
     */
    @RequestMapping("addProject")
    @ResponseBody
    public Message addProject(Project project){
        projectService.addProject(project);
        return new Message(Message.STATUS_SUCCESS,"添加成功");
    }

    /**
     * 项目修改页面
     * @param model
     * @param id
     * @return
     */
    @RequestMapping("updateProjectView")
    public String updateProjectView(Model model,int id){
        model.addAttribute("userList",userService.getUserList());
        model.addAttribute(projectService.findProjectById(id));
        return "projectEdit";
    }
    /**
     * 新增项目
     * @param project
     * @return
     */
    @RequestMapping("updateProject")
    @ResponseBody
    public Message updateProject(Project project){
        projectService.updateProject(project);
        return new Message(Message.STATUS_SUCCESS,"修改成功");
    }
}
